package de.gwtprime.server.servlets;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * Redirect to google login service
 * @author jan
 *
 */
public class LoginGoogleServlet extends LoginSuperServlet {
	
	private static final long serialVersionUID = 6674422695032376211L;
	private static Logger log = Logger.getLogger(LoginGoogleServlet.class.getName());

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String callbackURL = buildCallBackURL(request, 1);
		UserService userService = UserServiceFactory.getUserService();
		String googleLoginUrl = userService.createLoginURL(callbackURL);
		log.info("Going to Google login URL: " + googleLoginUrl);
		
		storeLastPageToSession(request);
		response.sendRedirect(googleLoginUrl);
	}

	
}